<template>
    <view class="goodsList-item" >
        <view class="goodsList-item-left">
            <radio :checked="goods.goods_state" color="#ff93a7" v-if="showRadio" @click="radioClickHandler"></radio>
            <image class="goods-pic" :src="goods.goods_small_logo || defaultPic" @click="goto(goods.goods_id)"></image>
        </view>
        <view class="goodsList-item-right">
            <view class="goods-name" @click="goto(goods.goods_id)">
                <text> {{ goods.goods_name }}</text>
            </view>
            <view class="goods-price">
                <text>￥{{ Number(goods.goods_price).toFixed(2) }}</text>
                <uni-number-box :min="1" :max="20" :value="goods.goods_count" v-if="showRadio" @change="numChangeHandler"></uni-number-box>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        props: {
            goods: {
                type: Object,
                default: {}
            },
            showRadio: {
                type: Boolean,
                // 默认情况下不会显示radio组件
                default: false
            }
        },
        data() {
            return {
                defaultPic: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.U94Z89XV8xiBeEgFrTG-IgAAAA?rs=1&pid=ImgDetMain'
            }
        },
        methods: {
            radioClickHandler() {
                this.$emit('radio-change',{
                    goods_id: this.goods.goods_id,
                    goods_state: !this.goods.goods_state
                })
            },
            numChangeHandler(count) {
                this.$emit('number-change',{
                    goods_id: this.goods.goods_id,
                    goods_count: Number(count)
                })
            },
            goto(goods_id){
                uni.navigateTo({
                    url:`/subpackage/goods_detail/goods_detail?goods_id=${goods_id}`
                })
            }
        },
    }
</script>


<style lang="scss">
    .goodsList-item {
        display: flex;
        border-bottom: 1px solid #f0f0f0;
        padding: 10px 5px;

        .goodsList-item-left {
            margin-right: 5px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .goods-pic {
                width: 120px;
                height: 120px;
                display: block;
            }
        }

        .goodsList-item-right {
            display: flex;
            flex: 1;
            flex-direction: column;
            justify-content: space-between;

            .goods-name {
                height: 60ox;
                font-size: 13px;
                /*强制英文单词断行*/
                word-break: break-all;
                /*超出的部分隐藏*/
                overflow: hidden;
                /*超出的部分用省略号显示*/
                text-overflow: ellipsis;
                /*弹性伸缩盒子模型显示*/
                display: -webkit-box;
                /*限制在一个块元素显示的文本的行数*/
                -webkit-line-clamp: 3;
                /*设置或检索伸缩盒对象的子元素的排列方式*/
                -webkit-box-orient: vertical;

            }

            .goods-price {
                font-size: 16px;
                font-weight: bold;
                color: #cc0404;
                display: flex;
                justify-content: space-between;
            }
        }
    }
</style>
